$(function () {
    // function getQueryString(name) {
    //     var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    //     var r = window.location.search.substr(1).match(reg);
    //     if (r != null) return decodeURIComponent(r[2]); return null;
    // }
    // console.log(getQueryString("classId"),getQueryString("className"))

    // $('#classId').val(localStorage.getItem("classId"))
    // $('#className').val(localStorage.getItem("className"))
    $('#id').val(sessionStorage.getItem("id"))
    $('#classId').val(sessionStorage.getItem("classId"))
    $('#author').val(sessionStorage.getItem("author"))
    $('#name').val(sessionStorage.getItem("name"))
    $('#desc').val(sessionStorage.getItem("desc"))
    $('#chap').val(sessionStorage.getItem("chap"))
    $('.novel-edit').change(function () {
        console.log(8888888888888888888888888,$(this).val())
        console.log($(this).val(),sessionStorage.getItem($(this).attr('id')),44444,)
        if($(this).val() ===''|| $(this).val().trim().length===0){
            $(this).focus().parent().addClass("has-error")
            $("#btnEdit").attr("disabled","disabled")
        }
        else if($(this).val()===sessionStorage.getItem($(this).attr('id'))) {
            $("#btnEdit").attr("disabled", "disabled")
            $(this).parent().removeClass("has-success")
        }
        else {
            $(this).parent().removeClass("has-error").addClass("has-success")
            $("#btnEdit").removeAttr("disabled")
        }
    })

    $("#btnEdit").click(function () {
        // console.log(localStorage.getItem("className"),11221)
        // let id = $("#id").val()
        // let author = $('#author').val()
        // let description = $('#description').val()
        // let name = $('#name').val()
        // let chapterCount = $('#chapter-count').val()
        // if(author==null || description=null){
        //     $('#className').parent().addClass("has-error")
        //     $('#className').focus()
        // } else {

        let url = "/novel?id="+$("#id").val()+"&author="+$('#author').val()
                    +"&description="+$('#desc').val()
                    +"&name="+$('#name').val()
                    +"&chapterCount="+$('#chap').val()
        console.log(url)
            $.ajax({
                url:url,
                type:"POST",
                success: function (data) {
                    console.log(data)
                    location.href="index.html";
                },
                error: function (data) {
                    console.log(data)
                }
            })
        // }

    })
})